PROJECT(k3dsdk)

FILE(GLOB HEADERS *.h)
FILE(GLOB SOURCES *.cpp)

LIST(SORT HEADERS)
LIST(SORT SOURCES)

IF(WIN32 AND K3D_COMPILER_GCC)
	# For some reason, serialization_xml.cpp takes *forever* to build with optimizations enabled
	SET_SOURCE_FILES_PROPERTIES(serialization_xml.cpp PROPERTIES COMPILE_FLAGS -O0)
ENDIF(WIN32 AND K3D_COMPILER_GCC)

CONFIGURE_FILE(${k3dsdk_SOURCE_DIR}/k3d-i18n-config.h.in ${k3dsdk_BINARY_DIR}/k3d-i18n-config.h)
CONFIGURE_FILE(${k3dsdk_SOURCE_DIR}/k3d-ngui-config.h.in ${k3dsdk_BINARY_DIR}/k3d-ngui-config.h)
CONFIGURE_FILE(${k3dsdk_SOURCE_DIR}/k3d-parallel-config.h.in ${k3dsdk_BINARY_DIR}/k3d-parallel-config.h)
CONFIGURE_FILE(${k3dsdk_SOURCE_DIR}/k3d-platform-config.h.in ${k3dsdk_BINARY_DIR}/k3d-platform-config.h)
CONFIGURE_FILE(${k3dsdk_SOURCE_DIR}/k3d-version-config.h.in ${k3dsdk_BINARY_DIR}/k3d-version-config.h)

INCLUDE_DIRECTORIES(
	${k3d_SOURCE_DIR}
	${k3dsdk_BINARY_DIR}
	${Boost_INCLUDE_DIRS}
	${k3dsdk_SOURCE_DIR}/gil
	${K3D_GLIBMM_INCLUDE_DIRS}
	${K3D_SIGC_INCLUDE_DIRS}
	${K3D_OPENGL_INCLUDE_DIR}
	)

IF(K3D_ENABLE_PARALLEL)
	INCLUDE_DIRECTORIES(${K3D_TBB_INCLUDE_DIR})
ENDIF(K3D_ENABLE_PARALLEL)

IF(K3D_ENABLE_PROFILING)
    INCLUDE_DIRECTORIES(${K3D_GOOGLE_PERFTOOLS_INCLUDE_DIR})
ENDIF(K3D_ENABLE_PROFILING)

INCLUDE_DIRECTORIES(${K3D_XML_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${K3D_ZLIB_INCLUDE_DIRS})

LINK_DIRECTORIES(${K3D_GLIBMM_LIB_DIRS})
LINK_DIRECTORIES(${K3D_SIGC_LIB_DIRS})
LINK_DIRECTORIES(${K3D_ZLIB_LIB_DIRS})

K3D_ADD_LIBRARY(k3dsdk SHARED ${HEADERS} ${SOURCES})
K3D_GENERATE_DEF_FILE(k3dsdk)

TARGET_LINK_LIBRARIES(k3dsdk
	${K3D_GLIBMM_LIBS}
	${K3D_SIGC_LIBS}
	${K3D_XML_LIB}
	${K3D_ZLIB_LIBS}
	${K3D_OPENGL_LIBRARIES}
	k3dsdk-half
	k3dsdk-sgi-tesselator
	k3dsdk-glew
	k3dsdk-parallel
	${Boost_PROGRAM_OPTIONS_LIBRARY}
	${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
	)

IF(K3D_ENABLE_NLS)
	INCLUDE_DIRECTORIES(${K3D_INTL_INCLUDE_DIRS})
	TARGET_LINK_LIBRARIES(k3dsdk ${K3D_INTL_LIBS})
ENDIF(K3D_ENABLE_NLS)

IF(K3D_ENABLE_PROFILING)
    TARGET_LINK_LIBRARIES(k3dsdk ${K3D_PROFILER_LIBRARY})
ENDIF(K3D_ENABLE_PROFILING)

IF(WIN32)
	TARGET_LINK_LIBRARIES(k3dsdk ole32)
	TARGET_LINK_LIBRARIES(k3dsdk ws2_32)
ENDIF(WIN32)

ADD_SUBDIRECTORY(Half)
ADD_SUBDIRECTORY(expression)
ADD_SUBDIRECTORY(ftgl)
ADD_SUBDIRECTORY(gl)
ADD_SUBDIRECTORY(glew)
ADD_SUBDIRECTORY(parallel)
ADD_SUBDIRECTORY(resource)
ADD_SUBDIRECTORY(sgi_tesselator)
ADD_SUBDIRECTORY(subdivision_surface)

K3D_ADD_SUBDIRECTORY(ngui REQUIRES K3D_BUILD_NGUI_MODULE)
K3D_ADD_SUBDIRECTORY(qtui REQUIRES K3D_BUILD_QTUI_MODULE)
K3D_ADD_SUBDIRECTORY(python REQUIRES K3D_ENABLE_PYTHON)

INSTALL(TARGETS k3dsdk
	RUNTIME DESTINATION bin
	LIBRARY DESTINATION ${K3D_LIBDIR}
	ARCHIVE DESTINATION ${K3D_LIBDIR})
INSTALL(FILES ${HEADERS} DESTINATION include/k3d/k3dsdk)

INSTALL(FILES ${k3dsdk_BINARY_DIR}/k3d-i18n-config.h DESTINATION ${K3D_LIBDIR}/k3d/include)
INSTALL(FILES ${k3dsdk_BINARY_DIR}/k3d-ngui-config.h DESTINATION ${K3D_LIBDIR}/k3d/include)
INSTALL(FILES ${k3dsdk_BINARY_DIR}/k3d-parallel-config.h DESTINATION ${K3D_LIBDIR}/k3d/include)
INSTALL(FILES ${k3dsdk_BINARY_DIR}/k3d-platform-config.h DESTINATION ${K3D_LIBDIR}/k3d/include)
INSTALL(FILES ${k3dsdk_BINARY_DIR}/k3d-version-config.h DESTINATION ${K3D_LIBDIR}/k3d/include)

